#ifndef __APP_DEMO_ROBOT_CAR_H__
#define __APP_DEMO_ROBOT_CAR_H__


#define     CAR_CONTROL_DEMO_TASK_STAK_SIZE   (1024*10)
#define     CAR_CONTROL_DEMO_TASK_PRIORITY    (25)
#define     DISTANCE_BETWEEN_CAR_AND_OBSTACLE (20)
#define     KEY_INTERRUPT_PROTECT_TIME        (30)
#define     CAR_TURN_LEFT                     (0)
#define     CAR_TURN_RIGHT                    (1)

// ??????????
#define     CAR_SPEED_LEVEL_0                 (0)    // Stop
#define     CAR_SPEED_LEVEL_1                 (30)   // Low speed
#define     CAR_SPEED_LEVEL_2                 (50)   // Medium-low speed
#define     CAR_SPEED_LEVEL_3                 (70)   // Medium-high speed
#define     CAR_SPEED_LEVEL_4                 (90)   // High speed
#define     CAR_SPEED_LEVEL_5                 (100)  // Maximum speed
#define     CAR_SPEED_MAX_LEVEL               (5)    // Maximum level (6 levels total: 0-5)

// PWM continuous speed control definitions
#define     PWM_FREQ_DEFAULT                  (1000) // PWM frequency 1KHz
#define     PWM_PERIOD_US                     (1000) // PWM period 1000us (1ms)
#define     PWM_RESOLUTION                    (100)  // PWM resolution 100 levels
#define     SPEED_TRANSITION_STEP             (2)    // Speed transition step

typedef enum {
    CAR_STOP_STATUS = 0,
    CAR_OBSTACLE_AVOIDANCE_STATUS, 
    CAR_TRACE_STATUS
} CarStatus;

void switch_init(void);
void interrupt_monitor(void);

// ????????????????
void car_speed_init(void);
void car_speed_up(void);
void car_speed_down(void);
unsigned char get_current_speed_level(void);           // ??????????OLED???
unsigned char get_current_actual_speed_level(void);    // ????????????????
unsigned char get_display_speed(void);                 // ?????????
unsigned char get_actual_speed_from_display(unsigned char display_speed); // ??????
void set_motor_speed(unsigned char left_speed, unsigned char right_speed);

// Motor control functions (implemented in robot_l9110s.c)
void set_motor_speed_level(unsigned char speed_level);
unsigned char get_motor_speed_level(void);
void motor_pwm_control(void);
unsigned int get_current_speed_delay(void);

// Motor status variables (defined in robot_l9110s.c)
extern unsigned char g_left_motor_enable;
extern unsigned char g_right_motor_enable;
extern unsigned char g_left_motor_direction;
extern unsigned char g_right_motor_direction;

#endif